<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>7.1 递归</title>
    <script>
        function printNum(number) {
            console.log(number);
            --number;
            if (number > 0) {
                arguments.callee(number);
            }
        }

        printNum(10);

        function printNum2() {

        }

        let f = (function f1(num) {
            if (num <= 1) {
                return 1;
            } else {
                return num * f1(num - 1);
            }
        });

        console.log(f(10));

        console.log('----------------');

        function createFunctions() {
            var result = new Array();
            for (var i = 0; i < 10; i++) {
                result[i] = function () {
                    return i;
                };
            }
            return result;
        }

        let arr1 = createFunctions();
        console.log(arr1[1]());

        console.log('----------------');

        function create2() {
            let arr = new Array();
            for (let i = 0; i < 10; i++) {
                arr[i] = function () {
                    return i;
                };
            }
            return arr;
        }

        let arr2 = create2();
        console.log(arr2[1]());
        console.log(arr2[9]());

        console.log('----------------');
        let info = '哈哈哈哈哈哈';

        function create3() {
            var arr = new Array();
            for (var i = 0; i < 10; i++) {
                arr[i] = (function (i) {
                    return function () {
                        console.log(this.info + ' : ' + i);
                        return i;
                    };
                })(i);
            }
            return arr;
        }

        var arr3 = create3();
        console.log(arr3[1]());
        console.log(arr3[2]());
        console.log(arr3[3]());
        console.log(arr3[4]());

    </script>
</head>
<body>

</body>
</html>